//
//  PeopleDetaileModel.m
//  markmap
//
//  Created by 甘世清 on 2024/5/14.
//

#import "PeopleDetaileModel.h"
#import "AddModel.h"
@implementation PeopleDetaileModel
+(void)SQ_peopleDetaile:(NSMutableArray*)jsonArray model:(PeopleDetaileModel*)model{
    [jsonArray removeAllObjects];
   
    if ([model.remark isNotEmpty]) {
        [jsonArray addObject:model.remark]; //如果有简介
    }
    if ([model.preference isNotEmpty]) {
        NSArray * array = [model.preference componentsSeparatedByString:@","];
        for (NSString * name in array) {
            [jsonArray addObject:name];
        }
    }
    if (jsonArray.count<=0) {
        [jsonArray addObject:SQNSLocalString(@"这家伙很懒,什么也没有填写!")];
    }
    [model.dynamicDto setObject:model.name forKey:@"name"];
    [model.dynamicDto setObject:model.portrait forKey:@"portrait"];
    [model.dynamicDto setObject:@(model.gender) forKey:@"gender"];
    [model.dynamicDto setObject:@(model.realStatus) forKey:@"realStatus"];
}


+ (NSDictionary *)mj_replacedKeyFromPropertyName{
   return @{@"userid": @"id"};
}
- (float)dynamicHeight{
    FunyModel * model = [FunyModel mj_objectWithKeyValues:self.dynamicDto];
    CGSize size = [Manager SQ_boundingAttributedStringRectWithSize:CGSizeMake(SCREEN_WIDETH-24, MAXFLOAT) lineSpace:2 textFont:FONT_REGULAR(14) string:model.content];
    
    float height = 78 + size.height + 12;
    if ([model.imgs isNotEmpty]) {
        NSArray * array = [model.imgs componentsSeparatedByString:@","];
        if (array.count ==1) {
            NSString * urlstring = array.firstObject;
            NSArray * sizeArray = [urlstring componentsSeparatedByString:@"&"];
            if (sizeArray.count >2) {
                NSString * imageWidth = [NSString stringWithFormat:@"%@",[sizeArray objectAtIndex:1]];
                NSString * imageHieght = [NSString stringWithFormat:@"%@",[sizeArray objectAtIndex:2]];
                float width = [imageWidth floatValue];
                float heightimage = [imageHieght floatValue];
                if (width < heightimage) {
                   if (heightimage > SCREEN_WIDETH-50) {
                       heightimage = SCREEN_WIDETH-50;
                       width = height/[imageHieght floatValue] * [imageWidth floatValue];
                   }
               } else {
                   if (width > SCREEN_WIDETH-50) {
                       width = SCREEN_WIDETH-50;
                       heightimage = width/[imageWidth floatValue] * [imageHieght floatValue];
                   }
               }
                height = height + heightimage+10;
            } else {
                height = height + SCREEN_WIDETH-30;
            }
        } else if (array.count ==2) {
            height = height + SCREEN_WIDETH/2.f;
        }else if (array.count ==3) {
            height = height + SCREEN_WIDETH/3.f;
        }else if (array.count ==4) {
            height = height + ((SCREEN_WIDETH-34)/2.f-20)*2;
        }else if (array.count ==5||array.count ==6) {
            height = height + SCREEN_WIDETH/3.f*2+10;
        }else{
            height = height + SCREEN_WIDETH;
        }
    }  
    return height;
}
    
-(CGSize)cellSize{
    float cellW  = (SCREEN_WIDETH-30)/2.f-1;
    CGSize size = [Manager SQ_boundingAttributedStringRectWithSize:CGSizeMake(cellW, MAXFLOAT) lineSpace:2 textFont:FONT_REGULAR(11) string:self.remark];
    if (size.height < 20) {
        size.height = 20;
    }
    return CGSizeMake(cellW, size.height + 270);
}
@end
